<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class Model_Tag extends Zend_Db_Table_Abstract{
    protected $_name = "tags";
    public function getAllTags(){
        return $this->fetchAll();
    }
    public function getTagByID($id){
        return $this->find($id)->current();
    }
    public function createTag($name, $link){
        try{
        $row = $this->createRow();
        $row->name = $name;
        $row->link = $link;
        $row->save();
        $id = $this->_db->lastInsertId();
        if($id)
            return true;
        else
            return false;
        }  catch (Exception $ex){
            echo $ex->getTraceAsString();
            return false;
        }
    }
    public function updateTag($id, $name, $link){
        try{
            $data = array("name"=>$name, "link"=>$link);
            return $this->update($data, 'id ='.$id);
        }  catch (Exception $ex){
            echo $ex->getTraceAsString();
            return false;
        }
    }
    public function deleteTag($id){

		if(is_numeric($id)){
			return $this->delete('id='.$id);
		}else{
			return $this->delete('id in ('.$id.')');
		}
	}
}
?>
